<?php


namespace app\api\controller\v1;

use app\api\model\Theme as ThemeModel;
use app\api\validate\IDCollection;
use app\api\validate\IDMustBePostiveInt;
use app\lib\exception\ThemeException;

class Theme
{
    /**
     * @url /theme?ids=1,2,3
     */
    public function getSimpleLIst($ids = '')
    {
        (new IDCollection())->goCheck();

        $ids = explode(',', $ids);
        $result = ThemeModel::with('topicImg,headImg')->select($ids);

        if (!$result) {
            throw new ThemeException();
        }
        return $result;
    }

    /**
     * @param $id
     */
    public function getComplexOne($id)
    {
        (new IDMustBePostiveInt())->goCheck();

        $theme = ThemeModel::getThemeWithProducts($id);
        if (!$theme) {
            throw new ThemeException();
        }
        return $theme;
    }
}